<template>
  <div>
    <customDialog
      :title="`失败原因图片`"
      :dialogVisible="dialogVisible"
      @close="closeDialog"
      :showFoot="false"
      width="1100"
    >
      <div class="table_box_wrapper">
        <template v-for="(item, index) in tableData" :key="index">
          <el-image
            class="reason_img"
            :src="item"
            :zoom-rate="1.2"
            :preview-src-list="[item]"
            :initial-index="1"
            fit="contain"
          />
        </template>
      </div>
    </customDialog>
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive, toRefs } from "vue";
import customTable from "@/components/CustomTable/index.vue";
import customDialog from "@/components/CustomDialog/index.vue";
import { getEvidences, getMaterial } from "@/api/operateCenter/episode/index";
import moment from "moment";

const dialogVisible = ref(false);
const loading = ref<boolean>(false);
const form = {
  appId: undefined,
  mediaId: undefined,
  materialId: undefined,
};
const formData = ref(Object.assign({}, form));
const tableData = ref<Array<any>>([]);
const url = ref<string>("");
const srcList = ref<Array<any>>([]);

// 获取文件图片
const getEvidencesList = (val = 0) => {
  loading.value = true;
  getEvidences(formData.value)
    .then((res: Record<string, any>) => {
      res.data.map((item: string) => {
        getMaterialList(item);
      });
    })
    .finally(() => {
      loading.value = false;
    });
};

const getMaterialList = (val: string) => {
  let params = {
    appId: formData.value.appId,
    materialId: val,
  };
  getMaterial(params).then((res: any) => {
    const url = URL.createObjectURL(res);
    tableData.value.push(url);
  });
};

const closeDialog = () => {
  dialogVisible.value = false;
  tableData.value = [];
};

// 父级电子显示dialog
const showDialog = (val: Record<string, any>, str = undefined) => {
  dialogVisible.value = true;
  formData.value.appId = val?.appId;
  formData.value.mediaId = val?.mediaId;
  getEvidencesList();
};

defineExpose({
  showDialog,
});
</script>

<style scoped lang="scss">
.table_box_wrapper {
  display: flex;
  flex-wrap: wrap;
}

.reason_img {
  width: 180px;
  height: 180px;
  margin: 10px;
  background-color: #f2f6fc;
}
</style>
